use data/raw/defund-openended-deidentified.dta, clear

capture program drop clean_string 
program define clean_string  
replace `0'=ustrlower(`0')
replace `0' = subinstr(`0', char(160), "", .)
replace `0' = subinstr(`0', char(128), "", .)
replace `0' = subinstr(`0', char(147), "", .)
replace `0' = subinstr(`0', char(150), "", .)
replace `0' = subinstr(`0', char(165), "", .)
replace `0' = subinstr(`0', char(166), "", .)
replace `0' = subinstr(`0', char(184), "", .)
replace `0' = subinstr(`0', char(194), "", .)
replace `0' = subinstr(`0', char(195), "", .)
replace `0' = subinstr(`0', char(226), "", .)
replace `0' = subinstr(`0', char(0127),char(0903), .)
replace `0' = strtrim(`0')
end 

rename hand_coding handcoding
clean_string handcoding  

replace handcoding = subinstr(handcoding, "persasion", "persuasion", .) 
replace handcoding = subinstr(handcoding, "persuasion", "persuasion", .)  
replace handcoding = "rationale, persuasion" if handcoding == "rationale,persuasion"


* Generate demographic and control variables
gen ind = party=="Independent"
lab var ind "Independent"
drop party

gen partisan = .
replace partisan = 2 if liberal == "Very conservative"
replace partisan = 1 if liberal == "Conservative"
replace partisan = 0 if liberal == "Neither liberal nor conservative"
replace partisan = -1 if liberal == "Liberal"
replace partisan = -2 if liberal == "Very liberal"
label var partisan "Partisan leaning"


destring year, replace
gen age = 2021-year
lab var age "Age"
drop year

gen age2 = age^2
lab var age2 "Age squared"
gen hisp = hispanic=="Yes"
lab var hisp "Spanish, Hispanic, or Latino"
drop hispanic
gen male = sex == "Male"
lab var male "Male"
drop sex

lab var education "Education level"

gen white = race=="Caucasian/White"
lab var white "White"
lab var race "Race"

save "data/working/defund-openended.dta", replace
